package com.android.place360.place_search_result;

import java.util.*;

import com.android.place360.place_detail.DetailRequest;
import com.android.place360.place_detail.DetailResult;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

public class ListResultAdapter extends BaseAdapter {

	ArrayList<PlaceItem> listPlaces;
	int resource;
	Context context;

	public ListResultAdapter(Context context, int textViewResourceId,
			ArrayList<PlaceItem> objects) {
		this.context = context;
		resource = textViewResourceId;
		listPlaces = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = new CustomViewGroup(context);
		}

		final PlaceItem item = listPlaces.get(position);

		if (convertView != null) {
			ImageView icon = ((CustomViewGroup) convertView).getIcon();
			TextView placeNameTextView = ((CustomViewGroup) convertView)
					.getPlaceName();
			TextView addressTextView = ((CustomViewGroup) convertView)
					.getAddress();
			TextView distance = ((CustomViewGroup) convertView).getDistance();

			placeNameTextView.setText(position + 1 + ". "
					+ item.getPlaceResult().getName());
			if (item.getDetailResult() != null)
				addressTextView.setText(item.getDetailResult()
						.getFormatted_address());
			distance.setText(item.getDistanceString());
			
			// icon.setImageResource(R.drawable.place_pin);
			// addressTextView.setText(item.getPlaceItem().getStreetAddress().trim());

		}
		return convertView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listPlaces.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return listPlaces.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

}
